package com.ruoyi.system.utils;

import java.net.URI;
import java.net.URL;
 
public class PathConverter {
    public static void main(String[] args) {
        String localPath = "D:\\user\\问题.xls";
        String httpPath = convertToHttpPath(localPath);
        System.out.println(httpPath);
    }

    public static String convertToHttpPath(String localPath) {
        // 转换Windows路径为标准的URI格式
        String uriPath = localPath.replace("\\", "/");
        // 转换为相对于服务器根目录的路径
        String relativePath = uriPath.substring(1); // 去掉盘符
        // 创建HTTP基础URL
        URI baseUri = URI.create("http://localhost");
        // 使用URI的resolve方法来合并路径
        URI httpUri = baseUri.resolve("/" + relativePath);
        return httpUri.toString();
    }
}